﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Model;
using common;
using System.Data;
using System.Data.SqlClient;

namespace Dao {
    /// <summary>
    /// StateDao 的摘要说明
    /// </summary>
    public class StateDao
    {
        private string sqlStr;
        public StateDao()
        {
        }

        public List<State> GetOrderState()
        {

            string sqlStr = "select * from orderstate";

            DataTable dataTable = SqlHelper.GetDataTable(sqlStr);
            List<State> list = null;
            if (dataTable.Rows.Count > 0)
            {
                list = new List<State>();
                foreach (DataRow row in dataTable.Rows)
                {
                    State state = new State();
                    state.Id = Convert.ToInt32(row["id"]);
                    state.StateName = row["orderstate"].ToString();
                    list.Add(state);
                }
            }
            return list;
        }

        public String GetOrderStateById(int stateId)
        {

            string sqlStr = "select orderstate from orderstate where id=@stateId";
            SqlParameter[] parameters =
            {
                 new SqlParameter("@stateId", stateId)
            };

            DataTable dataTable = SqlHelper.GetDataTable(sqlStr,parameters);
            string state = "";
            if (dataTable.Rows.Count > 0)
            {
                state = (string)dataTable.Rows[0][0];
            }
            return state;
        }

        public List<State> GetBookState()
        {

            string sqlStr = "select * from bookstate";

            DataTable dataTable = SqlHelper.GetDataTable(sqlStr);
            List<State> list = null;
            if (dataTable.Rows.Count > 0)
            {
                list = new List<State>();
                foreach (DataRow row in dataTable.Rows)
                {
                    State state = new State();
                    state.Id = Convert.ToInt32(row["id"]);
                    state.StateName = row["stateName"].ToString();
                    list.Add(state);
                }
            }
            return list;
        }

        public String GetBookStateById(int stateId)
        {

            string sqlStr = "select stateName from bookstate where id=@stateId";
            SqlParameter[] parameters =
            {
                 new SqlParameter("@stateId", stateId)
            };

            DataTable dataTable = SqlHelper.GetDataTable(sqlStr, parameters);
            string state = "";
            if (dataTable.Rows.Count > 0)
            {
                state = (string)dataTable.Rows[0][0];
            }
            return state;
        }

    }
}
